package com.iemp.service.impl.page;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iemp.bean.example.FileExample;
import com.iemp.bean.example.NoticeExample;
import com.iemp.bean.impl.File;
import com.iemp.bean.impl.Notice;
import com.iemp.dao.NoticeMapper;
import com.iemp.service.base.AbstractPageService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class NoticeServiceImpl extends AbstractPageService<Notice> {

    private final NoticeMapper mapper;

    public NoticeServiceImpl(NoticeMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Integer deleteById(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Notice selectById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int insertSelective(Notice entity) {
        entity.setNoticePublishTime(new Date());
        return mapper.insertSelective(entity);
    }

    @Override
    public int updateByIdSelective(Notice entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public PageInfo findAllByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(mapper.selectByExample(new NoticeExample()));
    }
}
